export default abstract class AbstractData {
  protected data: Map<string, any> = new Map();

  /**
   * 获取自定义值.
   * @param key
   * @param defaultValue
   */
  public getData<T>(key: string, defaultValue?: T): T {
    if (! this.data.has(key)) {
      return defaultValue
    }
    return this.data.get(key)
  }

  /**
   * 设置自定义值.
   * @param key
   * @param value
   */
  public setData<T>(key: string, value: T): void {
    this.data.set(key, value)
  }

  /**
   * 自定义值是否存在.
   * @param key
   */
  public hasData(key: string): boolean {
    return this.data.has(key)
  }

  /**
   * 删除自定义值.
   * @param key
   */
  public deleteData(key: string): void {
    this.data.delete(key)
  }

  /**
   * 清空自定义值.
   */
  public clearData(): void {
    this.data.clear()
  }

}
